//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    order_number: '',
    detail: {},
    imgUrls: [],
    state: '',
    name: '',
    phone: '',
    state_tip:'',
    consignee:'',//退货收货人
    phone_no:0,//退货联系电话
    site: { //发货地址
      site_name: '',
      site_phone: '',
      site_detail: '',
    },
  },
  onLoad(options) {
    // console.log('options',options)
    this.setData({
      order_number: options.order_number,
      name: options.name,
      phone: options.phone
    })
    this.getStatus(options.order_number)
  },
  // 取消售后
  cancelStatus() {
    var that = this;
    var token = wx.getStorageSync('token')
    wx.request({
      url: 'https://www.zbq888.cn/api/v1/user/order/after/cancel',
      method: 'post',
      data: {
        "order_number": that.data.order_number
      },
      header: {
        'ontent-type': 'application/json',
        'client': 1,
        'token': token
      },
      success(res) {
        // console.log(res)
        wx.showToast({
          title: res.data.tip,
          icon: 'none',
        })
      }
    })
  },
  // 重新申请售后
  goShouHou() {
    wx.navigateTo({
      url: '../afterSale/afterSale?name=' + this.data.name + '&phone=' + this.data.phone + "&order_number=" + this.data.order_number
    })
  },
  // 卖家同意 填写快递信息
  kuaiDi() {
    wx.navigateTo({
      url: '../kuaidi/kuaidi?name=' + this.data.site.site_name + '&phone_no=' + this.data.site.site_phone + "&order_number=" + this.data.order_number + "&address=" + this.data.site.site_detail,
    })
  },
  //获取售后结果
  getStatus(order_number) {
    var that = this;
    var token = wx.getStorageSync('token')
    wx.request({
      url: 'https://www.zbq888.cn/api/v1/user/order/after/detail',
      method: 'post',
      data: {
        "order_number": order_number
      },
      header: {
        'content-type': 'application/json', // 默认值
        "client": 1,
        'token': token
      },
      success(res) {
        if (res.data.after_img !== '') {
          var imgUrls = res.data.after_img.split(',');
          that.setData({
            imgUrls: imgUrls
          })
        }
        if (res.data.after_state == 1) {
          that.data.state = '等待卖家审核'
        } else if (res.data.after_state == 2) {
          that.data.state = '卖家同意'
        } else if (res.data.after_state == 3) {
          that.data.state = '卖家拒绝'
        } else if (res.data.after_state == 4) {
          that.data.state = '等待卖家签收 '
        } else if (res.data.after_state == 5) {
          that.data.state = '售后已被卖家拒绝2次'
        } else if (res.data.after_state == 6) {
          that.data.state = '已完成'
        } else if (res.data.after_state == 7) {
          that.data.state = '拒绝签收（售后失败）'
        } else if (res.data.after_state == 8) {
          that.data.state = '已取消'
        }
        that.setData({
          detail: res.data,
          site: { //发货信息
            site_name: res.data.consignee,
            site_phone: res.data.phone_no,
            site_detail: res.data.address,
          },
        })
      }
    })
  },
})